#include "Command.h"
#include "BattleEngine.h"

Command::Command(QIcon *on, QIcon *off, QString nm, QString desc, QString tp, void* batEng) {

    onImage = on;
    offImage = off;
    name = nm;
    description = desc;
    type = tp;
    engine = batEng;
    setIcon(*off);
    setGeometry(0,0,25,25);
    hide();
    interfaceConnect();
}

void Command::moveToEndPoint(QTimer* moveTimer) {
    move(*startPoint);
    localTimer = moveTimer;
    connect(moveTimer,SIGNAL(timeout()),this,SLOT(moveToEnd()));
}

void Command::moveToEnd() {
    if (endPoint->y() < y())
        move(x(), y() - 1);
    else if(endPoint->y() > y())
        move(x(), y() + 1);
    else if(endPoint->x() < x())
        move(x() - 1, y());
    else if(endPoint->x() > x())
        move(x() + 1, y());

    if(endPoint->x() == x() && endPoint->y() == y())
        disconnect(localTimer,SIGNAL(timeout()),this,SLOT(moveToEnd()));
}

void Command::setPoints(QPoint* start, QPoint* end) {
    startPoint = start;
    endPoint = end;
}

QString Command::getType() {
    return type;
}

void Command::interfaceConnect(){
    ((BattleEngine*)engine)->connectToInterface(this);
}

QString Command::getDesc() {
    return description;
}

QString Command::getName() {
    return name;
}

QIcon* Command::getOnImage() {
    return onImage;
}

QIcon* Command::getOffImage() {
    return offImage;
}

Command::~Command() {
    //delete this;
}
